package com.jiuzhou.guanwang.jzcp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiuzhou.guanwang.jzcp.R;

import java.util.List;

public class OpenNumberAdapter extends RecyclerView.Adapter<OpenNumberAdapter.MyViewHolder> {
    private List<String> data;
    private Context mContext;

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView codeTv;

        public MyViewHolder(View itemView) {
            super(itemView);
            this.codeTv = (TextView) itemView.findViewById(R.id.tv_code);
        }
    }

    public void setData(List<String> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    public OpenNumberAdapter(Context context) {
        this.mContext = context;
    }

    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(this.mContext).inflate(R.layout.item_opne_code, parent, false));
    }

    public void onBindViewHolder(MyViewHolder holder, int position) {
        if (!TextUtils.isEmpty((CharSequence) this.data.get(position))) {
            if (((String) this.data.get(position)).contains("特别")) {
                holder.codeTv.setBackgroundResource(R.drawable.ic_ball_blue1);
                holder.codeTv.setText(((String) this.data.get(position)).substring(0, ((String) this.data.get(position)).indexOf("特")));
                return;
            }
            holder.codeTv.setBackgroundResource(R.drawable.ic_ball_red1);
            holder.codeTv.setText((CharSequence) this.data.get(position));
        }
    }

    public int getItemCount() {
        return this.data == null ? 0 : this.data.size();
    }
}
